/**
 * 添加Form
 * @author sux
 * @param {Object} width
 * @memberOf {TypeName} 
 */
addLeaveForm = Ext.extend(Ext.form.FormPanel,{
	id: 'leaveForm',
	//url: 'emp_save.action',
	//构造方法中的width参数为TabPanel的宽度
	constructor: function(width){
		width = (width-750)/4;
		Ext.QuickTips.init();
		var deptObject = new DepartJob("所在部门","emp.department.deptId"); //实例化部门
		jobObject = new Job("职位","emp.job.jobId",deptObject); //实例化职位
		jobObject.on('expand', function(comboBox){
			var deptId = Ext.getCmp("deptValue所在部门").getValue();
			this.getStore().load({
				params: {
					deptId: deptId
				}
			});
		});
		var reader = new Ext.data.JsonReader({},[{
			name: 'leaveId', mapping: 'leaveId'
		},{//json时间格式转为ext,time为json中显示的一部分
			name: 'leaveTime', mapping: 'leaveTime', dateFormat : 'time', type: 'date'
		},{
			name: 'leaveReason', mapping: 'leaveReason'
		}]);
		addLeaveForm.superclass.constructor.call(this,{
			//var windowWidth =   window.screen.availWidth;获取屏幕宽度
			//bodyStyle: 'margin-left:'+width+'px;', //将下面的panel显示在中间
			frame: true,
			reader: reader,
			items: [{
				width: 768/2,
				layout: 'table',//表格布局
				labelAlign: 'right',
				labelWidth: 80,
				frame: true,
				layoutConfig: {//3列
					columns: 3
				},
				items: [{
					layout: 'form',
					//columnWidth: .33, // column列布局
					defaults: {
						xtype: 'textfield',
						width: 150
					},
					items: [{
						xtype: 'datefield',
						fieldLabel: '请假日期',
						name: 'leave.leaveTime',
						format: 'Y-m-d',
						allowBlank: false,
						editable: false,
						msgTarget: 'side',
						blankText: '日期不能为空',
						emptyText: '不能为空'
					},{
						fieldLabel: '请假原因',
						msgTarget: 'side',
						blankText: '请假原因不能为空',
						emptyText: '不能为空',
						xtype: 'textarea',
						height: 80,
						width: '100%',
						name: 'leave.leaveReason'
					}]
				},{
					layout: 'form',
					defaults: {
						xtype: 'textfield',
						width: 150
					}
				}]
				},{
				xtype: 'panel',
				width: 750/2,
				buttonAlign: 'center',
				buttons: [{
					text: '提交',
					handler: function(){
						if(!Ext.getCmp('leaveForm').getForm().isValid()){
		    				return;
		    			}
						Ext.getCmp('leaveForm').getForm().submit({
							url: 'leave-saveOrUpdate.action',
							method: 'post',
							waitTitle: '提示',
							waitMsg: '正在保存数据...',
							success: saveSuccess,
							failure: saveFailure,
							scope: this
						});
					}
				},{
					text: '关闭',
					handler: function(){
						//Ext.getCmp('empForm').getForm().reset();
						//Ext.get('emp_photo').dom.src = 'img/default.gif';
						Ext.getCmp('leaveUpdateWinId').destroy();
					}
				}]
			}]
		});
	}
});

//保存成功操作
saveSuccess = function(form, action){
	Ext.Msg.confirm('提示', action.result.msg, function(button, text){
		Ext.getCmp('leaveForm').getForm().reset();
		if(button == "yes"){
			Ext.getCmp('leaveUpdateWinId').destroy();//销毁窗体
			Ext.getCmp("leaveInfo").getStore().load({
			params: {
				deptId: "",
				start: 0,
				limit: 20
			}
		});
		}
	});
};
//保存失败操作
saveFailure = function(form, action){
	Ext.Msg.alert('提示','连接失败');
};